{include file="../common/header"}
<!--页面主要内容-->
<main class="lyear-layout-content">

    <div class="container-fluid p-t-15">

        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body">
                        <div class="form-group" >
                            <label for="platename">板块名称</label>
                            <input type="hidden" class="form-control" id="id" value="{$plate.id}" disabled>
                            <input type="text" class="form-control" id="platename" value="{$plate.platename}" placeholder="请输入板块名称">
                        </div>
                        <div class="form-group file-group">
                            <label for="plateicon">icon图标</label>
                            <div class="input-group">
                                <input type="text" id="plateicon" class="form-control file-value" name="plateicon" value="{$plate.plateicon}" placeholder="icon图标">
                                <input type="file" accaccept=".png,.jpg,.jpeg,.bmp,.gif" style="display: none">
                                <div class="input-group-btn">
                                    <button class="btn btn-default file-browser" type="button">上传图片</button>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="appname">app名称</label>
                            <input type="text" class="form-control" id="appname" value="{$plate.appname}" disabled>
                        </div>
                        <button type="button" onclick="updateplate()" class="btn btn-primary mb-2">提交</button>
                        <button type="button" class="btn btn-default mb-2" onclick="javascript:history.back(-1);return false;">返 回
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>
<!--End 页面主要内容-->
</div>
</div>
{include file="../common/footer"}
<script>
    function updateplate(){
        var l = $('body').lyearloading({
            opacity: 0.2,
            spinnerSize: 'lg',
            spinnerText: '后台处理中，请稍后...',
            textColorClass: 'text-info',
            spinnerColorClass: 'text-info'
        });
        var id = $.trim($("#id").val());
        var platename = $.trim($("#platename").val());
        var plateicon = $.trim($("#plateicon").val());
        $.ajax({
            type: "POST",
            url: "{:url('/admin/bbs/updateplate')}",
            data: {
                id: id,
                platename: platename,
                plateicon: plateicon,
            },
            dataType: "json",
            success: function (data) {
                setTimeout(function() {
                    l.destroy();
                }, 1e3)
                if (data.code == 200){
                    $.notify({
                        message: data.msg
                    },{
                        placement: {
                            from: "top",
                            align: "center"
                        },
                        type: 'success'
                    });
                }else{
                    $.notify({
                        message: data.msg
                    },{
                        placement: {
                            from: "top",
                            align: "center"
                        },
                        // settings
                        type: 'danger'
                    });
                }
            }
        })
    }
    $(document).ready(function() {
        $(document).on('click', '.file-browser', function() {
            var $browser = $(this);
            var file = $browser.closest('.file-group').find('[type="file"]');
            file.on( 'click', function(e) {
                e.stopPropagation();
            });
            file.trigger('click');
        });

        $(document).on('change', '.file-group [type="file"]', function() {
            var l = $('body').lyearloading({
                opacity: 0.2,
                spinnerSize: 'lg',
                spinnerText: '后台处理中，请稍后...',
                textColorClass: 'text-info',
                spinnerColorClass: 'text-info'
            });
            var $this    = $(this);
            var $input   = $(this)[0];
            var $len     = $input.files.length;
            var formFile = new FormData();

            if ($len == 0) {
                return false;
            } else {
                var fileAccaccept = $this.attr('accaccept');
                var fileType      = $input.files[0].type;
                var type          = (fileType.substr(fileType.lastIndexOf("/") + 1)).toLowerCase();

                if (!type || fileAccaccept.indexOf(type) == -1) {
                    $.notify({
                        message: '您上传图片的类型不符合(.jpg|.jpeg|.gif|.png|.bmp)',
                    },{
                        placement: {
                            from: "top",
                            align: "center"
                        },
                        type: 'success'
                    });
                    l.destroy();
                    return false;
                }
                formFile.append("file", $input.files[0]);
            }

            var data = formFile;

            $.ajax({
                url: "{:url('/admin/app/upload')}",
                data: data,
                type: "POST",
                dataType: "json",
                //上传文件无需缓存
                cache: false,
                //用于对data参数进行序列化处理 这里必须false
                processData: false,
                //必须
                contentType: false,
                success: function (res) {
                    setTimeout(function() {
                        l.destroy();
                    }, 1e3)
                    if (res.code == 200) {
                        $.notify({
                            message: res.msg
                        },{
                            placement: {
                                from: "top",
                                align: "center"
                            },
                            type: 'success'
                        });
                        //console.log(res.data[0].filePath);
                        $this.closest('.file-group').find('.file-value').val(res.data[0].fullPath);
                    } else {
                        $.notify({
                            message: "系统错误"
                        },{
                            placement: {
                                from: "top",
                                align: "center"
                            },
                            // settings
                            type: 'danger'
                        });
                    }
                },
            });
        });
    });


</script>

</body>

</html>
